home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch5 / FrmPrint.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-04-05  |  2.6 KB  |  88 lines

  1. VERSION 5.00
  2. Begin VB.Form FrmPrintForm 
  3.    Caption         =   "FrmPrint"
  4.    ClientHeight    =   3405
  5.    ClientLeft      =   2640
  6.    ClientTop       =   1635
  7.    ClientWidth     =   3405
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   3405
  11.    ScaleWidth      =   3405
  12.    Begin VB.Menu mnuFile 
  13.       Caption         =   "&File"
  14.       Begin VB.Menu mnuFilePrint 
  15.          Caption         =   "&Print"
  16.       End
  17.    End
  18. Attribute VB_Name = "FrmPrintForm"
  19. Attribute VB_GlobalNameSpace = False
  20. Attribute VB_Creatable = False
  21. Attribute VB_PredeclaredId = True
  22. Attribute VB_Exposed = False
  23. Option Explicit
  24. ' Draw a Bowditch curve on the indicated object.
  25. Private Sub DrawPicture(obj As Object)
  26. Const PI = 3.14159265
  27. Dim x As Integer
  28. Dim y As Integer
  29. Dim t As Single
  30. Dim maxt As Single
  31. Dim dt As Single
  32.     ' Draw the curve.
  33.     maxt = PI * 8
  34.     dt = maxt / 200
  35.     obj.CurrentX = 0
  36.     obj.CurrentY = 0
  37.     For t = dt To maxt + dt / 2 Step dt
  38.         obj.Line -(Sin(0.75 * t), Sin(t))
  39.     Next t
  40. End Sub
  41. ' Set the printer's scale properties so it will
  42. ' print the object at the correct size, centered
  43. ' in the printable area.
  44. Private Sub SetPrinterScale(obj As Object)
  45. Dim pwid As Single
  46. Dim phgt As Single
  47. Dim xmid As Single
  48. Dim ymid As Single
  49.         
  50.     ' Get the printer's dimensions in twips.
  51.     pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbTwips)
  52.     phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbTwips)
  53.     ' Convert the printer's dimensions into the
  54.     ' object's coordinates.
  55.     pwid = obj.ScaleX(pwid, vbTwips, obj.ScaleMode)
  56.     phgt = obj.ScaleY(phgt, vbTwips, obj.ScaleMode)
  57.     ' Compute the center of the object.
  58.     xmid = obj.ScaleLeft + obj.ScaleWidth / 2
  59.     ymid = obj.ScaleTop + obj.ScaleHeight / 2
  60.     ' Pass the coordinates of the upper left and
  61.     ' lower right corners into the Scale method.
  62.     Printer.Scale _
  63.         (xmid - pwid / 2, ymid - phgt / 2)- _
  64.         (xmid + pwid / 2, ymid + phgt / 2)
  65. End Sub
  66. ' Draw the picture on the form.
  67. Private Sub Form_Paint()
  68.     Cls
  69.     DrawPicture Me
  70. End Sub
  71. ' Reset the form scale properties so the picture
  72. ' fills the form.
  73. Private Sub Form_Resize()
  74.     Me.Scale (-1.1, -1.1)-(1.1, 1.1)
  75.     Me.Refresh
  76. End Sub
  77. ' Draw the picture on the Printer object.
  78. Private Sub mnuFilePrint_Click()
  79.     MousePointer = vbHourglass
  80.     DoEvents
  81.     ' Set the printer's scale properties.
  82.     SetPrinterScale Me
  83.     ' Draw the picture.
  84.     DrawPicture Printer
  85.     Printer.EndDoc
  86.     MousePointer = vbDefault
  87. End Sub
  88.